/*
 * @Author: silence
 * @Date: 2022-04-27 14:40:43
 * @LastEditors: silence
 * @LastEditTime: 2022-04-27 15:32:23
 * @Description: 自定义文本
 */
import 'package:flutter/material.dart';

class MyText extends StatelessWidget {
  final String? data;

  /// 默认显示1行
  final int? maxLines;

  /// 默认省略
  final TextOverflow? overflow;

  /// 将逻辑像素改成1.0，不根据手机分辨率进行变化
  final double? textScaleFactor;

  /// 如果设置了style，则color、backgroundColor、fontSize等设置无效
  final TextStyle? style;
  final TextAlign? textAlign;

  /// 文本显示方向
  final TextDirection? textDirection;

  /// 快捷设置文本常用属性
  final Color? color;
  final Color? backgroundColor;
  final double? fontSize;
  final FontWeight? fontWeight;
  final double? lineHeight;

  /// 字体
  final String? fontFamily;

  const MyText(this.data,
      {Key? key,
      this.maxLines = 1,
      this.overflow = TextOverflow.ellipsis,
      this.textScaleFactor = 1.0,
      this.style,
      this.textAlign,
      this.textDirection,
      this.color,
      this.backgroundColor,
      this.fontSize,
      this.fontWeight,
      this.lineHeight,
      this.fontFamily})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    TextStyle? style = this.style ??
        TextStyle(
            color: color,
            backgroundColor: backgroundColor,
            fontSize: fontSize,
            fontWeight: fontWeight,
            height: lineHeight,
            fontFamily: fontFamily);

    return Text(
      data ?? "",
      maxLines: maxLines,
      overflow: overflow,
      textScaleFactor: textScaleFactor,
      style: style,
      textAlign: textAlign,
      textDirection: textDirection,
    );
  }
}
